/**
 * @file tile.cpp
 * @brief Tile class methods implementation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * @author VestniK (Sergey N.Vidyuk) sir.vestnik@gmail.com
 * @date 4 Oct 2008
 */
#include "tile.h"

using namespace mjn;

Tile::Tile(Tile::TileSuits suit, Tile::TileRanks rank) {
   this->suit = suit;
   this->rank = rank;
}

Tile& Tile::operator= (const Tile& src) {
   suit = src.suit;
   rank = src.rank;
   return *this;
}

bool Tile::isValid() const {
   if ( (suit == NullSuit) || (rank == NullRank) ) {
      return false;
   }
   switch( rank ) {
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
         if ( (suit == Dot) || (suit == Bamboo) || (suit == Character) ) {
            return true;
         }
         break;

      case East:
      case South:
      case West:
      case North:
         if ( suit == Wind ) {
            return true;
         }
         break;

      case Red:
      case Green:
      case White:
         if ( suit == Dragon ) {
            return true;
         }
         break;

      case Plum:
      case Orchid:
      case Chrisantemium:
      case BambooFlower:
         if ( suit == Flower ) {
            return true;
         }
         break;

      case Spring:
      case Summer:
      case Autumn:
      case Winter:
         if ( suit == Season ) {
            return true;
         }
         break;

      default:
         return false;
   }
   return false;
}

bool Tile::operator== (const Tile& ptrn) const {
   if ( (suit == ptrn.suit) && (rank == ptrn.rank)  ) {
      return true;
   }
   return false;
}
